﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Threading.Tasks;
using System.Web.Mvc;
using ZFine.Application.Project;
using ZFine.Code;
using ZFine.Domain.Entity;
using System.Linq;
using System.Web;
using ZFine.Application;
using ZFine.Web;

namespace Logiv.WEB.Areas.Project.Controllers
{
    /// <summary>
    /// 上课时间
    /// </summary>
    public class CourseTimeController : BaseController
    {
        private CourseTimeApp serverApp = new CourseTimeApp();

        public override ActionResult Details()
        {
            var keyValue = Request.QueryString["keyValue"];
            var data = serverApp.GetForm(keyValue);
            if (data != null)
            {
                ViewData["objs"] = data;
            }
            else
            {
                ViewData["objs"] = null;
            }
            return View();
        }
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(Pagination pagination, string keyword)
        {
            try
            {
                var data = new
                {
                    rows = serverApp.GetList(pagination, keyword),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());

            }
            catch (Exception ex)
            {
                return null;
            }

        }
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = serverApp.GetForm(keyValue);
            return Content(data.ToJson());
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteForm(string keyValue)
        {
            int result = serverApp.DeleteForm(keyValue);
            if (result == -1)
            {
                return Warn("请选择要删除的项");
            }
            else if (result == -2)
            {
                return Warn("没有权限对此进行删除");
            }
            return Success("删除成功。");
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateInput(false)]
        public ActionResult SubmitForm(CourseTimeEntity NewsEntity, string keyValue)
        {
            int result = serverApp.SubmitForm(NewsEntity, keyValue);
            if (result == -1)
            {
                return Error("找不到对象");
            }
            else
            {
                return Success("操作成功。");
            }
        }
    }
}